package com.ly.hotel.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import android.content.res.Resources;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;


public class DateUtils {
	static Calendar ca = Calendar.getInstance();
	static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static String[] weeken ={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
	public static String[] weekzh ={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
	public static String[] weekjp ={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
	
	public static int getWeekOfDate(Date date){
		ca.setTime(date);
		return ca.get(Calendar.DAY_OF_WEEK);
	}
	
	public static String getWeekOfDateEN(Date date){
		return weeken[getWeekOfDate(date)-1];
		
	}
	
	public static String getWeekOfDateZH(Date date){
		return weekzh[getWeekOfDate(date)-1];
	}
	
	public static String getWeekOfDatejp(Date date){
		return weekjp[getWeekOfDate(date)-1];
	}
	
	public static String getDateOfMD(Date date){
		return new SimpleDateFormat("yyyy-MM-dd").format(date);
	}
	
	public static Date getTimeByZone(String zone){
		Calendar calendar = Calendar.getInstance();
		 int currentzone = TimeZone.getDefault().getRawOffset();
		 String fh="";
		 if(zone.indexOf("+")==-1){
			 fh = zone.substring(0,1);
		 }
		 
		 String sjstr = zone.substring(1);
		 String[] sjs = sjstr.split(":");
		 int timezone = Integer.parseInt(fh + ((Integer.parseInt(sjs[0])*60+Integer.parseInt(sjs[1]))*60*1000));
	     
	     Date date = new Date();
	     long t = date.getTime()+timezone-currentzone;
	     calendar.setTimeInMillis(t);
	        
		return calendar.getTime();
	}
	
	/**
	 * 格式化成年月日，带时分秒
	 * @param date
	 * @return
	 */
	public static String formatToLong(Date date) {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	}
	
	//格式化时间   如：  上午 9:00
	public static String getTimeString(Date date,Resources res)
	{
		SimpleDateFormat sdf=new  SimpleDateFormat("HH:mm");
//		if(date.getHours()<12)
//		{
//			return res.getString(R.string.AM).toString()+sdf.format(date);
//		}
//		return res.getString(R.string.PM).toString()+sdf.format(date);
		
		return sdf.format(date);
	}
	//格式化日期  如： 2008年1月8日
	public static String getDateString(Date date,Resources res)
	{
		SimpleDateFormat sdf = new  SimpleDateFormat(res.getString(R.string.DATE).toString(), MyApplication.getContext().getResources().getConfiguration().locale);
		return sdf.format(date);
	}

	public static String getDateString(Date date,String type,Locale locale)
	{
		SimpleDateFormat sdf = new  SimpleDateFormat(type, locale);
		return sdf.format(date);
	}

}
